// pages/fabu/fabu.js
import api from '../../utils/api'
import https from '../../utils/https'
import Toast from '@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nickName:'',
    price:'',
    describ:'', //商品描述
    category:'', //商品类别
    show:false,
    actions: [
      {
        name:'书籍'
    },
      {
        name:'文具'
    },
      {
        name:'美妆'
    },
      {
        name:'电子产品'
    },
      {
        name:'鞋包'
    },
      {
        name:'食品'
    }],
    fileList:[], //图片列表
  },
  show(){
    this.setData({
      show:true
    })
  },
  // 表单改变
  onChange1(event){
    this.setData({
      nickName:event.detail
    })
  },
  onChange2(event){
    this.setData({
      price:event.detail
    })
  },
  onChange3(event){
    this.setData({
      describ:event.detail
    })
  },
// 类别取消按钮
onClose(){
  this.setData({
    show:false
  })
},
onSelect(event){
  console.log(event.detail);
  this.setData({
    category:event.detail.name
  })
},
  afterRead(event) {
    const { file } = event.detail;
    console.log(file);
    let fileList=this.data.fileList
    fileList.push({url:file.url})
    this.setData({
      fileList:fileList
    })
  },
  // 删除图片
  delete(event){
    console.log(event);
    let fileList=this.data.fileList
    fileList.splice(event.detail.index,1)
    this.setData({
      fileList:fileList
    })
  },
  fubu(){
    let data=this.data
    https.post(api.api.fubuProduct,{nikeName:data.nickName,price:data.price,describ:data.describ,category:data.category,url:data.fileList[0].url,fabu:'true'
  }).then(res=>{
      console.log(res);
      if(res.data.data=='发布成功'){
        Toast.success('发布成功');
        this.setData({
          nickName:'',
          price:'',
          describ:'',
          category:'', 
          fileList:[],
        })
      }
    }).catch(res=>{
      console.log('res',res);
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

 
})